1

Closed

Getter Generates Wrong JavaScript Scope

description

The following TypeScript code
        get me(): PokerUser {
            var value = this.$scope.me;

            if (!value) {
                var userEmail = this.$cookies.userEmail;
                var userName = this.$cookies.userName;

                if (!userEmail)
                    return null;

                value = new PokerUser();
                value.Name = userName;
                value.Email = userEmail;
            }

            return value;
        }
generates the following JavaScript
        Object.defineProperty(PokerRoomCtrl.prototype, "me", {
            get: function () {
                this.value = this.$scope.me;;

                if (!value) {
                    this.userEmail = this.$cookies.userEmail;;
                    this.userName = this.$cookies.userName;;

                    if (!userEmail)
                        return null;

                    value = new PokerUser();
                    value.Name = userName;
                    value.Email = userEmail;
                }

                return value;
            },
            enumerable: true,
            configurable: true
        });
Which is causing the following error when run.
ReferenceError: value is not defined
    at PokerRoomCtrl.Object.defineProperty.get [as room] (http://localhost:1279/scripts/consensus.pokerRoom.js:77:22)
    at new PokerRoomCtrl (http://localhost:1279/scripts/consensus.pokerRoom.js:26:41)
    at invoke (http://localhost:1279/scripts/angular.js:2902:28)
    at Object.instantiate (http://localhost:1279/scripts/angular.js:2914:23)
    at $get (http://localhost:1279/scripts/angular.js:4805:24)
    at $get.i (http://localhost:1279/scripts/angular.js:4384:17)
    at forEach (http://localhost:1279/scripts/angular.js:137:20)
    at nodeLinkFn (http://localhost:1279/scripts/angular.js:4369:11)
    at compositeLinkFn (http://localhost:1279/scripts/angular.js:4015:15)
    at compositeLinkFn (http://localhost:1279/scripts/angular.js:4018:13) 
I can trace this back to the fact that the generated code is trying to use the class scope for the "value" variable instead of the local get property scope.
Closed Jun 28, 2013 at 7:14 PM by paulb
Thanks for reporting this is a duplicate of

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

comments