Visitar URL original
Break after equal on assignment if rhs is await/yield expression by seiyab · Pull Request #15204 · prettier/prettier · GitHub
Skip to content

Break after equal on assignment if rhs is await/yield expression - #15204

Merged
sosukesuzuki merged 9 commits into
prettier:mainfrom
seiyab:15196-break-after-eq-on-assignment-if-rhs-is-await
Aug 6, 2023
Merged

sosukesuzuki merged 9 commits into
prettier:mainfrom
seiyab:15196-break-after-eq-on-assignment-if-rhs-is-await

Conversation

@seiyab

@seiyab seiyab commented Aug 3, 2023 •

Copy link
Copy Markdown
Collaborator

Description

Works on #15196.

Feel free to stop this if it needs more discussions.

Fixes #15208

Checklist

  • I’ve added tests to confirm my change works.
  • (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✨

@seiyab seiyab changed the title 15196 break after equal on assignment if rhs is await expression Break after equal on assignment if rhs is await expression Aug 3, 2023
@@ -0,0 +1,9 @@
async function f() {

ghost Aug 3, 2023

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.

This is because Flow yields error on top-level await.

Comment thread src/language-js/print/assignment.js Outdated
const propertiesForPath = [];
for (;;) {
if (node.type === "UnaryExpression") {
if (node.type === "UnaryExpression" || node.type === "AwaitExpression") {

ghost Aug 3, 2023

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.

If we are doing this, I think we should treat yield the sameway, though it's not very common to be on RHS.

ghost Aug 3, 2023

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.

Ah, I agree with you,thank you.
Maybe typeof too?

ghost Aug 4, 2023

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 noticed typeof already breaks after =.
I try to work on yield.

@seiyab
seiyab marked this pull request as ready for review August 5, 2023 05:24
@seiyab
seiyab requested a review from fisker August 5, 2023 05:25
const longlonglonglonglonglonglong1 = yield qwertyuiop(asdfghjkl, zxcvbnm, qwertyuiop, asdfghjkl);
const longlonglonglonglonglonglong2 = yield { qwertyuiop: 1234567890, asdfghjkl: 1234567890, zxcvbnm: 123456789 };

const x = yield;

ghost Aug 5, 2023

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.

one test for yield* ... please.

ghost Aug 5, 2023

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 have missed it, thank you for feedback.

ghost left a comment

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.

Looks good to me.

@fisker fisker changed the title Break after equal on assignment if rhs is await expression Break after equal on assignment if rhs is await/yield expression Aug 5, 2023
@sosukesuzuki
sosukesuzuki merged commit bf0b304 into prettier:main Aug 6, 2023
@aarongoldenthal

ghost commented Aug 20, 2023 •

Copy link
Copy Markdown

While this change is definitely the better formatting option, changing this type of formatting is a breaking change.

@k4rli

ghost commented Aug 21, 2023

Copy link
Copy Markdown

Definitely a breaking change since it can affect much of codebase. Is there a way to use the old way?

@seiyab

ghost commented Aug 21, 2023 •

Copy link
Copy Markdown
Collaborator Author

There isn't way to avoid this on 3.0.2.
Prettier have usually changed format as a patch release.

Examples

Add 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
I hope it helps.

@seiyab
seiyab deleted the 15196-break-after-eq-on-assignment-if-rhs-is-await branch August 22, 2023 02:15
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.

line breaks after assignment instead of between parentheses / around parameters

5 participants