Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sinkValue for static methods #2599

Open
marcfallows opened this issue Aug 3, 2017 · 1 comment
Open

sinkValue for static methods #2599

marcfallows opened this issue Aug 3, 2017 · 1 comment

Comments

@marcfallows
Copy link

Related to: #2437

I have a class with a static method - output from TS that gets fed into CC looks like

var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "mobx"], function (require, exports, mobx) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var MyClass = (function () {
        function MyClass() {
        }
        MyClass.myMethod = function () {
            console.log('myMethod');
        };
        return MyClass;
    }());
    goog.reflect.sinkValue(MyClass.myMethod)
    __decorate([
        mobx.action
    ], MyClass, goog.reflect.objectProperty("myMethod", MyClass), null);
    MyClass.myMethod();
});

This gets compiled to:

(function() {
    function k(c) {
        k[" "](c);
        return c
    }
    k[" "] = function() {}
    ;
    var m = this && this.b || function(c, d, e, f) {
        var g = arguments.length, a = 3 > g ? d : null === f ? f = Object.getOwnPropertyDescriptor(d, e) : f, h;
        if ("object" === typeof Reflect && "function" === typeof Reflect.a)
            a = Reflect.a(c, d, e, f);
        else
            for (var l = c.length - 1; 0 <= l; l--)
                if (h = c[l])
                    a = (3 > g ? h(a) : 3 < g ? h(d, e, a) : h(d, e)) || a;
        return 3 < g && a && Object.defineProperty(d, e, a),
        a
    }
    ;
    function n() {}
    function p() {
        console.log("myMethod")
    }
    k(function() {
        return p
    });
    m([mobx.action], n, "c", null);
    p();
})();

You'll see that I am using sinkValue. And while the method is not technically inlined, it also is not kept on the class, so the decoration does not work.

@shicks
Copy link
Member

shicks commented Aug 9, 2017

I don't think goog.reflect.sinkValue does what you think. Is there any way you can get a @nocollapse on the method? There's talk of trying to teach DisambiguateProperties to back off on statics, which would make the annotation unnecessary, but that's probably still a ways away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants