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
Should not remove class fields when using flow #10039
Comments
@nicolo-ribaudo Thanks. I can try this out. |
@Ajay2507 it's yours! feel free to hit us up if you have any questions! |
@existentialism Cool. Thanks |
@existentialism @pajaydev is there some news with this issue? does still need help? thanks |
@lidoravitan I have done it, Some test are failing. I need to create a PR and get reviewed. |
@pajaydev cool thanks for the response |
@existentialism @nicolo-ribaudo I created this PR #10120 . this test |
@nicolo-ribaudo I fixed the test. Thanks for your help. I appreciate it. |
Summary: Flow implemented class fields while they were very early-stage, behind the `esproposal.class_instance_fields` and `esproposal.class_static_fields` flowconfig options. In current versions of the proposal, fields without initializers now default to `undefined`: [[design](https://github.com/tc39/proposal-class-fields#fields-without-initializers-are-set-to-undefined)] [[spec](https://tc39.es/proposal-class-fields/#sec-define-field)] Babel < 8 stripped uninitialized fields, which is not spec-compliant. Babel 8 changes to leaving the field and just removing the annotation, as you'd rightly expect, but making it impossible* to have type-only fields. [[babel issue](babel/babel#10039)] [[babel 8 notes](babel/babel#10746)] This diff introduces a `declare` syntax to provide a solution for type-only fields: ``` class C { declare foo: string; bar: string; } // becomes class C { bar; } ``` As far as Flow is concerned, both `foo` and `bar` are treated as before, as if they are `string`: ``` const x = new C; (x.foo: string); (x.bar: string); ``` Fixes #6811 [* technically you can use Flow comment syntax -- `class C { /*:: prop: string; */ }` but we don't want to require that] Reviewed By: samwgoldman Differential Revision: D20088452 fbshipit-source-id: f00299539c9387a55102e9a4e554a3b3bcb3498e
Summary: Flow implemented class fields while they were very early-stage, behind the `esproposal.class_instance_fields` and `esproposal.class_static_fields` flowconfig options. In current versions of the proposal, fields without initializers now default to `undefined`: [[design](https://github.com/tc39/proposal-class-fields#fields-without-initializers-are-set-to-undefined)] [[spec](https://tc39.es/proposal-class-fields/#sec-define-field)] Babel < 8 stripped uninitialized fields, which is not spec-compliant. Babel 8 changes to leaving the field and just removing the annotation, as you'd rightly expect, but making it impossible* to have type-only fields. [[babel issue](babel/babel#10039)] [[babel 8 notes](babel/babel#10746)] This diff introduces a `declare` syntax to provide a solution for type-only fields: ``` class C { declare foo: string; bar: string; } // becomes class C { bar; } ``` As far as Flow is concerned, both `foo` and `bar` are treated as before, as if they are `string`: ``` const x = new C; (x.foo: string); (x.bar: string); ``` Fixes #6811 [* technically you can use Flow comment syntax -- `class C { /*:: prop: string; */ }` but we don't want to require that] Reviewed By: samwgoldman Differential Revision: D20088452 fbshipit-source-id: f6102215d5cf13d91c073affd3adf85ce7d97a04
If the flow plugin runs before the class properties one (or if the class properties plugin isn't used), we remove uninitialize class fields:
currently becomes
while it should be
If someone still wants the old behavior, they can either use flow comments (as offically recommended), or use the
ignoreUninitialized
option which will soon be added to the class properties plugin (#9141).Is there anyone who wants to contribute for the first time to Babel? 🙂
If you don't know how to clone Babel, follow these steps: (you need to have
make
andyarn
available on your machine).git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel
yarn && make bootstrap
make watch
(ormake build
whenever you change a file)output.js
files in thetests/fixture
folder of@babel/plugin-transform-flow-strip-types
(if there are any)yarn jest [name-of-the-package-to-test]
to run the testsoutput.js
files and run the tests againmake test
tu run all the testsgit push
and open a PR!The text was updated successfully, but these errors were encountered: