Issue 1:
Bug Report

Current Behavior

Unable to use Immutable.Record's getter methods.

Input Code

mkdir /tmp/test && cd /tmp/test && npm init
npm i -S @babel/cli @babel/core @babel/preset-env @babel/preset-flow @babel/plugin-proposal-class-properties immutable@4.0.0-rc.10

(save the following as main.js)

// @flow

import Immutable from "immutable";

class T extends Immutable.Record({ items: Immutable.List() }) {
items: Immutable.List<number>;
}

console.log(new T().items, new T().get("items"));

Expected behavior/code

The expected behavior is for the generated code to not break getter methods on Immutable.Record attributes. main.js (above) works as expected when compilation is carried out as given below:

./node_modules/.bin/babel --no-babelrc --presets @babel/env --presets @babel/flow main.js|node

... which produces:

List [] List []

(new T().items getter works)

However, when the proposal-class-properties plugin is used, the getter on the Immutable.Record instance no longer works:

./node_modules/.bin/babel --no-babelrc --presets @babel/env --presets @babel/flow --plugins @babel/plugin-proposal-class-properties main.js|node

Produces:

undefined List []

Babel Configuration (.babelrc, package.json, cli command)

No .babelrc used. package.json below:

{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "main.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@babel/cli": "^7.1.0",
"@babel/core": "^7.1.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-flow": "^7.0.0",
"immutable": "^4.0.0-rc.10"
}
}

Environment

Babel version(s): v7.1.0

Node/npm version: Node 8.12.0

OS: Linux

Monorepo: N/A

How you are using Babel: cli

Possible Solution

N/A

Additional context/Screenshots

N/A

Issue 2:
Bug Report

Current Behavior

@babel/plugin-proposal-class-properties transform flow type annotation to a property assigning undefined.

this may caught statement order unexpected error.

Input Code

let code = `
class B {}
class Logger extends B {
log: {
error: boolean
}
silent: boolean
log = {
error: true
}
get silent(): boolean {
return this._silent;
}
set silent(val: boolean) {
this._silent = !!val;
if (!this.log) {
throw new Error('#log should not be nil.')
}
Object.keys(this.log).forEach(k => { /* do something... */ })
}
constructor() {
super()
}
}
`

let r = require("@babel/core").transform(code, {
"presets": [ "@babel/preset-flow" ],
"plugins": [
[ "@babel/plugin-proposal-class-properties", { "loose": true } ]
]
})
console.log(r.code)

ouput =>

class B {}

class Logger extends B {
get silent() {
return this._silent;
}

set silent(val) {
this._silent = !!val;

if (!this.log) {
throw new Error('#log should not be nil.') // <----- will throw if the annotation property assigning undefined
}

Object.keys(this.log).forEach(k => { /* do something... */ });
});
}

constructor() {
super();
this.log = void 0; <<<<<----
this.silent = void 0; <<<<<---- with setter defined.
this.log = {
error: true
};
}
}

Expected behavior/code

class B {}

class Logger extends B {
get silent() {
return this._silent;
}

set silent(val) {
this._silent = !!val;

if (!this.log) {
throw new Error('#log should not be nil.')
}

Object.keys(this.log).forEach(k => { /* do something... */ });
}

constructor() {
super();
this.log = {
error: true
};
}

}

Environment

Babel version(s): [e.g. v6.0.0, v7.0.0-beta.55]

Node/npm version: [e.g. Node 8/npm 5]

OS: [e.g. OSX 10.13.4]

Monorepo [e.g. yes/no/Lerna]

How you are using Babel: js

Possible Solution

Should strip the ClassProperty type of TypeAnnotation.