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

Incorrect Flow code generation when using optional ObjectTypeProperty & functions (T7564) #4461

Closed
babel-bot opened this issue Aug 18, 2016 · 1 comment
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@babel-bot
Copy link
Collaborator

Issue originally made by @zpao

Input code

declare type DraftEditorProps = {
  blockRendererFn?: (block: ContentBlock) => ?Object,
}

Description

For Draft (and other fbjs-based projects) we generate .js.flow files. We need to rewrite requires/imports in there, which we do via a babel transform. Ideally we'd only try to reprint that code instead of the whole tree (a la recast) but since the whole AST gets reprinted, it screws up in at least one case, optional object fields that are typed as functions.

I'm not a Flow expert so there might be another way to write the above code, but as written, it will get transformed to

declare type DraftEditorProps = {
  blockRendererFn?(block: ContentBlock): ?Object
};

which is invalid syntax.

I created #3663 as a potential solution but I'm not quite sure if I'm keeping the right semantics (if I understood @thejameskyle correctly, it's probably ok and can just be a style bikeshed). It seems there isn't enough info in the AST to determine if we're looking at a property written this way vs the way that is currently generated.

@hzoo
Copy link
Member

hzoo commented Sep 12, 2016

Fixed with #3663

@hzoo hzoo closed this as completed Sep 12, 2016
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 6, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

2 participants