Issue 1:
Bug Report

Current Behavior

Using typescript if I have a class that extends from another class fields in the extending class are overwritten with undefined. This happens after the constructor has finished and it occurs in the defineProperty.js of babelRuntime.

Input Code

class Base {
constructor(dto?){
if(dto){
this.updateFromDTO(dto);
}
}

updateFromDTO(dto) : this{
return this;
}
}

class Extends extends Base {
myField: string;

updateFromDTO(dto) {
super.updateFromDTO(dto);
console.log('I was called');
this.myField = "weee";
console.log(this.myField);
return this;
}
}

console.log(new Extends("123"));
// Console shows: 'I was Logged' and then 'weee'. Then the Extends object. The extends object has myField as undefined.

Expected behavior/code

For the field I set in Extends to still be set after the constructor is finished.

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

babel.config.js
const DEVELOPMENT = 'production' !== process.env.NODE_ENV

module.exports = {
presets: [
["@babel/preset-env", {useBuiltIns: "entry"}],
"@babel/preset-react",
"@babel/typescript"
],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-syntax-dynamic-import",
["@babel/plugin-transform-runtime", {"regenerator": true}],
"@babel/plugin-transform-classes",
],
}

package.json
{
"name": "webclient2.1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node_modules/.bin/webpack-dev-server --mode development --open --hot"
},
"author": "",
"license": "ISC",
"dependencies": {
"@answerrocket/iterable-map": "file:Core/packages/iterable-map",
"@answerrocket/itertools": "file:Core/packages/itertools",
"@answerrocket/organizer": "file:Core/packages/organizer",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/plugin-transform-classes": "^7.4.3",
"@babel/plugin-transform-runtime": "^7.4.3",
"@babel/runtime": "^7.4.3",
"catalog": "^3.6.0",
"fetch-intercept": "^2.3.1",
"lodash": "^4.17.11",
"lodash-es": "^4.17.11",
"moment": "^2.24.0",
"plotly.js": "^1.47.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-plotly.js": "^2.3.0",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-scripts": "2.1.8",
"ts-optchain": "^0.1.5",
"typescript": "^3.4.3",
"vega": "^5.3.5",
"vega-embed": "^4.0.0",
"vega-lite": "^3.1.0"
},
"devDependencies": {
"@types/lodash-es": "^4.17.3",
"@types/plotly.js": "^1.44.3",
"@types/react": "^16.8.13",
"@types/react-plotly.js": "^2.2.2",
"@types/react-router-dom": "^4.3.2",
"@babel/preset-typescript": "^7.3.3",
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.5",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"html-webpack-plugin": "^3.2.0",
"http-server": "^0.11.1",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.3.1"
}
}

webpack.config.js

const path = require("path");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");

const esDepIncludes = [/\/@customePackage\//]

module.exports = {
devtool: 'source-map',
entry: './src/index.tsx',
output: {
path: path.join(__dirname, "/dist"),
publicPath: "/dist/",
filename: "bundle.js"
},
module: {
rules: [
{
test: /\.(js|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react']
}
}
},
{
test: /\.[jt]sx?$/,
include: esDepIncludes,
loader: 'babel-loader',
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader'
}
]
}
]
},
resolve: {
extensions: ["*", ".js", ".jsx", ".tsx", ".ts"],
modules: [
path.join(__dirname, 'src'),
path.join(__dirname, 'private_modules'),
'node_modules'
],},
plugins: [
new HtmlWebPackPlugin({
hash: true,
filename: "index.tsx.ysx.jsx.html", //target html
template: "./public/index.html" //source html
})
]
}

Environment

Babel version(s): v6.23.0

Node/npm version: Node 10/npm 6.4.1

OS: OSX 10.14.4

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

How you are using Babel: webpack

Possible Solution

So far I haven't found a way around this

Issue 2:
Bug Report

Current Behavior

When a class (B) extends another class (A) and includes a type definition to narrow the type of something specified in class A, it will set the narrowed property's value to undefined. This diverges from the TSC behavior.

The output from the below code under babel is a, undefined.

Input Code

class A {
value: any
constructor(value: any) {
this.value = value
}
}

class B extends A {
value: string
}

document.write(`${new A('a').value}, ${new B('b').value}`)

Expected behavior/code

The output from the code should be a, b.

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

.babelrc:

{
"presets": [
"@babel/env",
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
]
}

Environment

Babel version(s): 7.1.6

Node/npm version: Node 10 / NPM 6

OS: Any OS

Monorepo: doesn't matter

How you are using Babel: loader

Possible Solution

It seems like babel is setting value = undefined in the class property - it needs to check if that value is defined in the parent before overwriting it.