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

Flow call expression generic with union type is parsed incorrectly with babylon parser #5460

Closed
FezVrasta opened this issue Nov 13, 2018 · 6 comments
Labels
lang:flow Issues affecting Flow-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! type:enhancement A potential new feature to be added, or an improvement to how we print something
Milestone

Comments

@FezVrasta
Copy link

Prettier 1.15.2
Playground link

Input:

const Theme = React.createContext<"light" | "dark">("light");

Output:

const Theme = (React.createContext < "light") | ("dark" > "light");

Expected behavior:

const Theme = React.createContext<"light" | "dark">("light");

This seems pretty bad.

@ikatyang
Copy link
Member

This looks like an edge case in babylon. As a workaround you could use --parser flow for now:

Prettier 1.15.2
Playground link

--parser flow

Input:

const Theme = React.createContext<"light" | "dark">("light");

Output:

const Theme = React.createContext<"light" | "dark">("light");

cc @existentialism

@ikatyang ikatyang added type:bug Issues identifying ugly output, or a defect in the program priority:high Code is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent! scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency lang:flow Issues affecting Flow-specific constructs (not general JS issues) labels Nov 13, 2018
@j-f1
Copy link
Member

j-f1 commented Nov 13, 2018

You can also use // prettier-ignore to work around the issue in the meantime.

@ikatyang

This comment has been minimized.

@suchipi suchipi changed the title can't use Flow with Prettier Call expression generic with union type is parsed incorrectly Nov 23, 2018
@suchipi suchipi changed the title Call expression generic with union type is parsed incorrectly Flow call expression generic with union type is parsed incorrectly with babylon parser Nov 23, 2018
@existentialism
Copy link
Collaborator

existentialism commented Nov 23, 2018

Since babel/babel#7934, the @babel/parser will only attempt to parse this if @flow pragma is present in the file or all option is passed to the flow plugin in its options (["flow", { all: true }])

Playground link with pragma

@j-f1 j-f1 added status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:option request Issues requesting a new option. We generally don’t accept these unless there is technical necessity. and removed priority:high Code is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent! scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency labels Nov 23, 2018
@j-f1
Copy link
Member

j-f1 commented Nov 23, 2018

Should Prettier add an option to enable all: true for the Babylon parser?

@ikatyang
Copy link
Member

How about adding a babylon-flow parser (and babylon-typescript for TS)?

@ikatyang ikatyang added type:enhancement A potential new feature to be added, or an improvement to how we print something and removed status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:bug Issues identifying ugly output, or a defect in the program type:option request Issues requesting a new option. We generally don’t accept these unless there is technical necessity. labels Nov 29, 2018
@ikatyang ikatyang added this to the 1.16 milestone Nov 29, 2018
@ikatyang ikatyang mentioned this issue Dec 27, 2018
3 tasks
@ikatyang ikatyang added the status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! label Dec 27, 2018
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Mar 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:flow Issues affecting Flow-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

No branches or pull requests

4 participants