Skip to content
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

TypeScript as regression (2.0.3) #7957

Closed
sosukesuzuki opened this issue Apr 5, 2020 · 8 comments · Fixed by #7958
Closed

TypeScript as regression (2.0.3) #7957

sosukesuzuki opened this issue Apr 5, 2020 · 8 comments · Fixed by #7958
Labels
lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@sosukesuzuki
Copy link
Member

sosukesuzuki commented Apr 5, 2020

Prettier 2.0.3
Playground link

# Options (if any):
--single-quote

Input:

function foo() {
  return {
    foo,
    foo,    
  } as FOO
}

Output:

function foo() {
  return (
    {
      foo,
      foo,
    } as FOO
  );
}

Expected behavior:

same as input

function foo() {
  return {
    foo,
    foo,    
  } as FOO
}
@sosukesuzuki sosukesuzuki added type:bug Issues identifying ugly output, or a defect in the program lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) labels Apr 5, 2020
@sosukesuzuki
Copy link
Member Author

I think we should revert #7869 and implement a handler for TSAsExpression that is different from the one for BinaryExpression.

@thorn0
Copy link
Member

thorn0 commented Apr 5, 2020

The problem arises only if the first operand is an object literal, right? So we rather need to handle this situation as a special case.

@domoritz
Copy link

domoritz commented Apr 6, 2020

Here are a few more examples where I am seeing this regression in my codebase in case it's helpful.
Screen Shot 2020-04-05 at 20 02 03
Screen Shot 2020-04-05 at 20 01 08
Screen Shot 2020-04-05 at 20 01 24
Screen Shot 2020-04-05 at 20 01 34

@domoritz
Copy link

domoritz commented Apr 6, 2020

Duplicate of #7956?

@thorn0
Copy link
Member

thorn0 commented Apr 6, 2020

@domoritz Could you please paste your examples as code not as screenshots so that we could use them for testing?

thorn0 added a commit to thorn0/prettier that referenced this issue Apr 6, 2020
thorn0 added a commit that referenced this issue Apr 6, 2020
…xpression" (#7958)

* Revert "[TypeScript] format TSAsExpression with same logic as BinaryExpression (#7869)"

This reverts commit 8a48ca2.

* add tests from #7956 and #7957

* more tests
@domoritz
Copy link

domoritz commented Apr 6, 2020

I thought screenshots show the changes well. I merely posted them so you can confirm that these are all "the first operand is an object literal". Let me know which code snippets you want (they are all taken from https://github.com/vega/vega-lite running 2.0.3 vs 2.0.2).

@thorn0
Copy link
Member

thorn0 commented Apr 6, 2020

@domoritz We've already solved this situation. Vega-Lite looks like a good codebase to test new versions of Prettier for regressions before releasing. I've made a note of it.

@domoritz
Copy link

domoritz commented Apr 6, 2020

Great! typescript-eslint is also using Vega-Lite as a test case: https://github.com/typescript-eslint/typescript-eslint/blob/master/tests/performance/fixtures/lint-real-repo/Dockerfile#L7

@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants