Skip to content

[7.0] Wrong this with class properties and arrow function #6153

@lixiaoyan

Description

@lixiaoyan

Babel version: 7.0.0-alpha.19
This bug only happens when using these two plugins together.

Input Code

const fn = () => {
  return class {
    fn = () => console.log(this);
  };
};

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

--plugins transform-class-properties,transform-es2015-arrow-functions

Expected Behavior

const fn = function () {
  return class {
    constructor() {
      var _this = this; // <--
      this.fn = function () {
        return console.log(_this);
      };
    }
  };
};

Current Behavior

var _this = this; // <--
const fn = function () {
  return class {
    constructor() {
      this.fn = function () {
        return console.log(_this);
      };
    }
  };
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.x: regressionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions