Skip to content

Commit

Permalink
Avoid removing uninitialized class fields with flow (#10120)
Browse files Browse the repository at this point in the history
* flow avoid removing class fields

* fix test case

* Update test

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
  • Loading branch information
pajaydev and nicolo-ribaudo committed Nov 2, 2020
1 parent 2eeb349 commit 635c7fd
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 13 deletions.
2 changes: 0 additions & 2 deletions packages/babel-plugin-transform-flow-strip-types/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ export default declare((api, opts) => {

if (node.declare) {
child.remove();
} else if (!allowDeclareFields && !node.value && !node.decorators) {
child.remove();
} else {
node.variance = null;
node.typeAnnotation = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class X {
foo = 2
bar: number = 3
baz: ?string
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugins": [
"transform-flow-strip-types",
"transform-classes",
"proposal-class-properties",
"external-helpers"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Test {
constructor() {
babelHelpers.defineProperty(this, "prop", void 0);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ class C1 {}

function f() {}

class C2 {}
class C2 {
p;
}

class C3 {}
class C3 {
p;
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ class Foo8 {

function foo19(requiredParam, optParam) {}

class Foo9 {}
class Foo9 {
prop1;
prop2;
}

class Foo10 {}
class Foo10 {
static prop1;
prop2;
}

class Foo11 {
#prop1;
Expand Down

0 comments on commit 635c7fd

Please sign in to comment.