Really really strange compiler issue in 0.9 version, related to "getters"

Topics: General
Jun 19, 2013 at 3:27 PM
There seems to be something really strange going on with getters in 0.9. I've struggled to come up with a small example. This one will compile into invalid javascript. If you change DummyCollection to Array, it seems to work. Also compiles fine if you make the SelectedValues getter a regular function .

module Test
{
export class DummyCollection
{
    Add(obj) { }
}

export class SelectorControl
{
    public get SelectedValues(): DummyCollection
    {
        var list = new DummyCollection();
        for (var i = 0; i < 2; i++)
        {
            list.Add("hello");
        }

        return list;
    }
}
}


Here is the resulting javascript; (see the for loop starting with "this.i")

var Test;
(function (Test) {
var DummyCollection = (function () {
    function DummyCollection() {
    }
    DummyCollection.prototype.Add = function (obj) {
    };
    return DummyCollection;
})();
Test.DummyCollection = DummyCollection;

var SelectorControl = (function () {
    function SelectorControl() {
    }
    Object.defineProperty(SelectorControl.prototype, "SelectedValues", {
        get: function () {
            this.list = new DummyCollection();;
            for (this.i = 0;; i < 2; i++) {
                list.Add("hello");
            }

            return list;
        },
        enumerable: true,
        configurable: true
    });
    return SelectorControl;
})();
Test.SelectorControl = SelectorControl;
})(Test || (Test = {}));
Jun 19, 2013 at 4:06 PM
Edited Jun 19, 2013 at 4:06 PM
I am seeing this as well, but not in every situation. Thanks for reproducing! If it does this, it changes every "var x" in the function to "this.x".
Jun 19, 2013 at 5:35 PM
Thanks for reporting we have an issue on this logged.

https://typescript.codeplex.com/workitem/1167