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
Break after equal on assignment if rhs is await/yield expression #15204
Break after equal on assignment if rhs is await/yield expression #15204
Conversation
@@ -0,0 +1,9 @@ | |||
async function f() { |
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.
This is because Flow yields error on top-level await.
src/language-js/print/assignment.js
Outdated
@@ -205,7 +205,7 @@ function shouldBreakAfterOperator(path, options, print, hasShortKey) { | |||
let node = rightNode; | |||
const propertiesForPath = []; | |||
for (;;) { | |||
if (node.type === "UnaryExpression") { | |||
if (node.type === "UnaryExpression" || node.type === "AwaitExpression") { |
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.
If we are doing this, I think we should treat yield
the sameway, though it's not very common to be on RHS.
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.
Ah, I agree with you,thank you.
Maybe typeof
too?
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 noticed typeof
already breaks after =
.
I try to work on yield
.
const longlonglonglonglonglonglong1 = yield qwertyuiop(asdfghjkl, zxcvbnm, qwertyuiop, asdfghjkl); | ||
const longlonglonglonglonglonglong2 = yield { qwertyuiop: 1234567890, asdfghjkl: 1234567890, zxcvbnm: 123456789 }; | ||
|
||
const x = yield; |
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.
one test for yield* ...
please.
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 have missed it, thank you for feedback.
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.
Looks good to me.
While this change is definitely the better formatting option, changing this type of formatting is a breaking change. |
Definitely a breaking change since it can affect much of codebase. Is there a way to use the old way? |
There isn't way to avoid this on 3.0.2. ExamplesAdd parentheses for TypeofTypeAnnotation to improve readability // Input
type A = (typeof node.children)[];
// Prettier 2.8.4
type A = typeof node.children[];
// Prettier 2.8.5
type A = (typeof node.children)[]; Break the LHS of type alias that has complex type parameters // Input
type FieldLayoutWith<
T extends string,
S extends unknown = { width: string }
> = {
type: T;
code: string;
size: S;
};
// Prettier 2.3.0
type FieldLayoutWith<T extends string, S extends unknown = { width: string }> =
{
type: T;
code: string;
size: S;
};
// Prettier 2.3.1
type FieldLayoutWith<
T extends string,
S extends unknown = { width: string }
> = {
type: T;
code: string;
size: S;
}; Personally, I automatically format only changed files to avoid changing huge amount of files by updating Prettier. https://stackoverflow.com/q/47610213/13195622 |
…ttier#15204) * add as-is test * break after equal on assignment if rhs is wait Discussion: prettier#15196 * rename test file * add as-is test * treat YieldExpression * add tests * add changelog * fix a bug * add test for delegated yield
Description
Works on #15196.
Feel free to stop this if it needs more discussions.
Fixes #15208
Checklist
(If changing the API or CLI) I’ve documented the changes I’ve made (in thedocs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨