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

Wrong constructor code generated when target is ES5 #48761

Closed
p-szm opened this issue Apr 19, 2022 · 0 comments · Fixed by #48765
Closed

Wrong constructor code generated when target is ES5 #48761

p-szm opened this issue Apr 19, 2022 · 0 comments · Fixed by #48765
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@p-szm
Copy link
Contributor

p-szm commented Apr 19, 2022

Bug Report

When this code is compiled to ES5 on nightly (4.7.0-dev.20220419)

class A {
    public constructor() {
        console.log("A")
    }
}

class B extends A  {
    constructor() {
        "ngInject";
        console.log("B")
        super();
    }
}

const b = new B();

it results with:

"use strict";
var __extends = (this && this.__extends) || (function () {
    /* implementation omitted for brevity */
})();
var A = (function () {
    function A() {
        console.log("A");
    }
    return A;
}());
var B = (function (_super) {
    __extends(B, _super);
    function B() {
        "ngInject";
        console.log("B");
        _this = _super.call(this) || this;
        return _super.call(this) || this;
    }
    return B;
}(A));
var b = new B();

In addition to _super.call(this) being duplicated, this code also fails at runtime because _this is not defined.

🔎 Search Terms

constructor, super, ngInject, directive, _this, this

🕗 Version & Regression Information

  • This changed between versions 4.5.x and 4.6.x

I expect #29374 to have introduced this regression. The code compiles and runs correctly on 4.5.x.

#48671 looks semi-related and it's already been fixed, but my issue seems a bit different.

⏯ Playground Link

https://www.typescriptlang.org/play?downlevelIteration=true&removeComments=true&target=1&ts=4.7.0-dev.20220419#code/MYGwhgzhAECC0G8BQBIADgVwEYgJbGmAHsA7CAFwCcNhyjKAKASkSWnY-eLKJAFMAdCCIBzBgCJY4pmw4BfJAqShIMAELQ+AD3J8SAExjxWnbhWq16zE5w7iSIgJIkAVn1riA3LNuFSEXkFhMXE1aR9bCAw0PkYmb04FJTNyaCxoAF5oEj4Ad2g1Zm8gA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants