Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
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
ignoreUninitializedoption 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
makeandyarnavailable on your machine).git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babelyarn && make bootstrapmake watch(ormake buildwhenever you change a file)output.jsfiles in thetests/fixturefolder of@babel/plugin-transform-flow-strip-types(if there are any)yarn jest [name-of-the-package-to-test]to run the testsoutput.jsfiles and run the tests againmake testtu run all the testsgit pushand open a PR!