Skip to content

Lexical this not captured for super element accessed calls #21081

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

Closed
weswigham opened this issue Jan 9, 2018 · 1 comment
Closed

Lexical this not captured for super element accessed calls #21081

weswigham opened this issue Jan 9, 2018 · 1 comment
Assignees
Labels
Bug A bug in TypeScript

Comments

@weswigham
Copy link
Member

TypeScript Version: 2.7.0-dev.201xxxxx

Code

class A { x() {} }

class B extends A {
    constructor() {
        super();
    }
    foo() {
        return () => {
            super["x"]();
        }
    }
}

Expected behavior:

var A = /** @class */ (function () {
    function A() {
    }
    A.prototype.x = function () { };
    return A;
}());
var B = /** @class */ (function (_super) {
    __extends(B, _super);
    function B() {
        return _super.call(this) || this;
    }
    B.prototype.foo = function () {
        var _this = this;
        return function () {
            _super.prototype["x"].call(_this);
        };
    };
    return B;
}(A));

Actual behavior:

var A = /** @class */ (function () {
    function A() {
    }
    A.prototype.x = function () { };
    return A;
}());
var B = /** @class */ (function (_super) {
    __extends(B, _super);
    function B() {
        return _super.call(this) || this;
    }
    B.prototype.foo = function () {
        return function () {
            _super.prototype["x"].call(this);
        };
    };
    return B;
}(A));

Related:
Found while working on #20125; will likely be included in the fix.

@weswigham weswigham added the Bug A bug in TypeScript label Jan 9, 2018
@weswigham weswigham added this to the TypeScript 2.7 milestone Jan 9, 2018
@weswigham weswigham self-assigned this Jan 9, 2018
@weswigham weswigham changed the title Lexical this not captures for super element accesses Lexical this not captured for super element accessed calls Jan 9, 2018
@weswigham
Copy link
Member Author

In the same vein, a super property reference that is never called causes an unused lexical this capture:

class A { x() {} }

class B extends A {
    constructor() {
        super();
    }
    foo() {
        return () => {
            super.x;
        }
    }
}

yields

var A = /** @class */ (function () {
    function A() {
    }
    A.prototype.x = function () { };
    return A;
}());
var B = /** @class */ (function (_super) {
    __extends(B, _super);
    function B() {
        return _super.call(this) || this;
    }
    B.prototype.foo = function () {
        var _this = this;
        return function () {
            _super.prototype.x;
        };
    };
    return B;
}(A));

but should yield

var A = /** @class */ (function () {
    function A() {
    }
    A.prototype.x = function () { };
    return A;
}());
var B = /** @class */ (function (_super) {
    __extends(B, _super);
    function B() {
        return _super.call(this) || this;
    }
    B.prototype.foo = function () {
        return function () {
            _super.prototype.x;
        };
    };
    return B;
}(A));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants