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

Comment get lost #9564

Closed
fisker opened this issue Nov 2, 2020 · 2 comments
Closed

Comment get lost #9564

fisker opened this issue Nov 2, 2020 · 2 comments
Labels
area:flow comment types lang:flow Issues affecting Flow-specific constructs (not general JS issues) type:intended Bug reports that actually turned out to be intended behavior

Comments

@fisker
Copy link
Member

fisker commented Nov 2, 2020

Prettier 2.1.2
Playground link

--parser flow

Input:

class A {
  /*::
  +isLookahead: boolean;
  */
  foo() {}
}

class A {
  /*::*/
  foo() {}
}

Output:

class A {
  +isLookahead: boolean;
  foo() {}
}

class A {
  foo() {}
}

Expected behavior:

@fisker fisker added type:bug Issues identifying ugly output, or a defect in the program lang:flow Issues affecting Flow-specific constructs (not general JS issues) labels Nov 2, 2020
@thorn0
Copy link
Member

thorn0 commented Nov 3, 2020

Unfortunately, this isn't solvable in the general case. Flow comments work on the token level, not on the AST level. So we can easily find an infinite amount of bugs like this in Prettier.

Example

Prettier 2.1.2
Playground link

--parser flow

Input:

/*:: if */ (x) + y;

Output:

if (x) +y;

This requires a fundamentally different solution.

A possible solution:

Prettier doesn't try to preserve these comments at all and just lets the parser parse them like normal code, which happens already for the Flow parser and can be enabled for Babel (#9074). Then, an option (or probably an option value for the parser option) controls the printer: the code can be printed either in the "Flow mode", where all the Flow comments are printed uncommented, as normal code, or in the "JS compatibility mode", in which all non-JS constructions are printed as Flow comments. AFAIK there can't be a good reason to mix the two in the same file.

@thorn0
Copy link
Member

thorn0 commented Oct 24, 2022

Closing as support for Flow comments was removed in #13687
Now this output is intended.

@thorn0 thorn0 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2022
@thorn0 thorn0 added type:intended Bug reports that actually turned out to be intended behavior and removed type:bug Issues identifying ugly output, or a defect in the program labels Oct 24, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:flow comment types lang:flow Issues affecting Flow-specific constructs (not general JS issues) type:intended Bug reports that actually turned out to be intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants