madskristensen / WebCompiler

Visual Studio extension for compiling LESS and Sass files
Other
451 stars 173 forks source link

Prototype function with keyword this compiled as undefined for keyword this #250

Open jkeath opened 8 years ago

jkeath commented 8 years ago

Installed product versions

When adding a prototype function to a class, if the prototype function has keyword "this" in it, it compiles to be "undefined". Example.

ES6 code

class MyClass {
    constructor() {
        this.MyProperty = 2;

    }
}

MyClass.prototype.toJSON = () => {
    let self = this;
}

Compiled Code

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

    this.MyProperty = 2;
};

MyClass.prototype.toJSON = function () {
    var self = undefined;
};

Steps to recreate

add the noted code above to a file and compile it.

Current behavior

It is incorrectly changing the keyword "this" to "undefined". This is obviously wrong and makes the code not do what is expected.

Expected behavior

It should result in the keyword "this" still be the keyword "this" after compile.

jkeath commented 8 years ago

I did notice if I change the code in ES6 for the prototype from this

ES6 Code

 MyClass.prototype.toJSON = () => {
  let self = this;
 }

To this

Compiled Code

 MyClass.prototype.toJSON = function() {
     let self = this;
 }

It correctly leaves keyword "this" as keyword "this".