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

JSDoc type cast parens are removed #218

Closed
Rich-Harris opened this issue May 3, 2021 · 1 comment · Fixed by #224
Closed

JSDoc type cast parens are removed #218

Rich-Harris opened this issue May 3, 2021 · 1 comment · Fixed by #224
Labels
bug Something isn't working

Comments

@Rich-Harris
Copy link
Member

When using JSDoc, it's common to do this sort of thing:

const x = /** @type {Foo} */ (a.b).c();

This tells TypeScript that a.b is of type Foo. Prettier will preserve those parentheses when processing JS files, but for whatever reason it fails to do so inside .svelte files, instead turning it into this:

const x = /** @type {Foo} */ a.b.c();
@dummdidumm
Copy link
Member

This is a tricky one .. Prettier's JS printer/parser respects that parentheses. We use the typescript parser though for the script tags, which does not preserve these, because in a TS file these JSDoc hints don't have meaning. So we probably need to switch the parser according to the script language.

@dummdidumm dummdidumm added the bug Something isn't working label May 3, 2021
dummdidumm pushed a commit to dummdidumm/prettier-plugin-svelte that referenced this issue May 10, 2021
If a script tag is assumed to be JS, use babel-ts now to format the contents. The formatter prints a little different, keeping parantheses in more places, which fixes sveltejs#218 . The change is not perfect because it would be better to know for sure that the language is JS, which we cannot know because of the possible language defaults.
dummdidumm added a commit that referenced this issue May 10, 2021
If a script tag is assumed to be JS, use babel-ts now to format the contents. The formatter prints a little different, keeping parantheses in more places, which fixes #218 . The change is not perfect because it would be better to know for sure that the language is JS, which we cannot know because of the possible language defaults.
@dummdidumm dummdidumm mentioned this issue Sep 28, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants