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
Conversation
fa59688
to
195b16a
Compare
packages/babel-parser/test/fixtures/flow/class-properties/declare-static-field/input.js
Show resolved
Hide resolved
@@ -0,0 +1,3 @@ | |||
class A { | |||
declare [foo] | |||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"
))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks 👍
a7d4f32
to
9a0bc5b
Compare
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 Can you also update https://babeljs.io/docs/en/babel-preset-flow#options? |
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