Skip to content

Fix generator missing parens around an arrow returning function type#10519

Merged
JLHwung merged 1 commit intomasterfrom
issue-10517
Oct 12, 2019
Merged

Fix generator missing parens around an arrow returning function type#10519
JLHwung merged 1 commit intomasterfrom
issue-10517

Conversation

@existentialism
Copy link
Copy Markdown
Member

Q                       A
Fixed Issues? Fixes #10517
Patch: Bug Fix? Y
Major: Breaking Change? N
Minor: New Feature? N
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

@existentialism existentialism added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: generator area: flow labels Oct 2, 2019
@existentialism existentialism changed the title Fix generator not printing parens around a return FunctionTypeAnnotation Fix generator missing parens around an arrow returning function type Oct 2, 2019
t.isArrayTypeAnnotation(parent) ||
// <T>(A: T): (T => T[]) => B => [A, B]
(t.isTypeAnnotation(parent) &&
t.isArrowFunctionExpression(printStack[printStack.length - 3]))
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.

What does printStack[printStack.length - 3]...... mean?

I assume this is related to Flow emit; the example syntax looks like invalid TypeScript.

Also, would the structure be the same if <T>(A: T): // ... (declaration signature) was written as <T>(A: T) => /... (expression signature)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's Flow emit related. I can add a comment, the printStack bit is just checking the grandparent (since these are only passed node, its parent, and the whole stack).

const bar7 = <T>(x) => {}; No newline at end of file
const bar7 = <T>(x) => {};

const bar8 = <T>(x: T): ((T) => T[]) => y => [x, y];
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.

hmm, I see. Maybe the correct output should be the one in the code comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was look into dropping the parens around (T) later, initial experiment looked like it touched a bunch of other fixtures.

@JLHwung JLHwung merged commit e28c8ac into master Oct 12, 2019
@JLHwung JLHwung deleted the issue-10517 branch October 12, 2019 01:22
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 11, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: flow outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parsing and generating flow type moves parentheses

4 participants