fbjs icon indicating copy to clipboard operation
fbjs copied to clipboard

[preset] Does not correctly transform arrow functions in property initializers

Open kassens opened this issue 9 years ago • 1 comments

The babel preset currently doesn't seem to correctly transform arrow functions as class properties:

class Foo {
  boundMethod = () => {
    return this;
  }
}

Output is this (note that _this is set to undefined instead of the instance).

"use strict";

var _this = undefined;

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Foo = function Foo() {
  _classCallCheck(this, Foo);

  this.boundMethod = function () {
    return _this;
  };
};

Code for repro: https://gist.github.com/kassens/ee845ea5db4a24a8127ecbb1390b63cf

kassens avatar Jul 28 '16 19:07 kassens

Related Babel task: https://phabricator.babeljs.io/T7274

kassens avatar Jul 28 '16 21:07 kassens