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

Implement support for declare on class fields with Flow #11178

Merged
merged 6 commits into from Mar 16, 2020

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Feb 27, 2020

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link babel/website#2196
Any Dependency Changes?
License MIT

Flow has recently landed support for declare fields, similar to TypeScript. (facebook/flow@11b7adb)

This PR implements parser support, and adds an allowDeclareFields option to the transform plugin to mirror the one of @babel/plugin-transform-typescript. In Babel 8 it will be enabled by default.

Even if it's not released yet in Flow, I'm adding this to the v7.9.0 milestone since Flow is released about once a week.

cc @mroch

@nicolo-ribaudo nicolo-ribaudo added PR: New Feature 🚀 A type of pull request used for our changelog categories area: flow pkg: parser labels Feb 27, 2020
@nicolo-ribaudo nicolo-ribaudo added this to the v7.9.0 milestone Feb 27, 2020
@nicolo-ribaudo nicolo-ribaudo force-pushed the flow-declare branch 3 times, most recently from fa59688 to 195b16a Compare February 27, 2020 14:38
@@ -0,0 +1,3 @@
class A {
declare [foo]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Flow does not support declared computed class fields yet: https://flow.org/try/#0G4QwTgBAZg9jEF4IEYDcAoAxgGxAZzwgEEIBvdCCAEwFMdwaIBtWGAXXQF8g

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not released yet.

Looking at the source code it doesn't seem to be disallowed (facebook/flow@11b7adb#diff-ca4a151bb3ce5bd8c11f1bc3b00036ebR619), but I don't see any test to confirm my assumption.

cc @@mroch should they be supported?

Copy link
Contributor

Choose a reason for hiding this comment

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

change the version selector in the top right to master and it parses.

It does error with "Computed property keys not supported.", but that's a type error, not a parse error (you can tell the difference on the CLI, but on Try Flow it's only in the JSON tab ("kind": "infer"))

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, thanks 👍

@nicolo-ribaudo
Copy link
Member Author

I split the error into two different errors to match Flow (https://github.com/facebook/flow/blob/cb99c11e0f620a981b6cea5c5ba2f02c7263679b/src/parser/parse_error.ml#L325-L326).

@nicolo-ribaudo nicolo-ribaudo added PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release and removed PR: Ready For Review labels Mar 5, 2020
@JLHwung
Copy link
Contributor

JLHwung commented Mar 6, 2020

@nicolo-ribaudo Can you also update https://babeljs.io/docs/en/babel-preset-flow#options?

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 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: parser PR: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants