Skip to content

Decorator emit incorrect within try block #35050

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
DanielRosenwasser opened this issue Nov 12, 2019 · 1 comment · Fixed by #41951
Closed

Decorator emit incorrect within try block #35050

DanielRosenwasser opened this issue Nov 12, 2019 · 1 comment · Fixed by #41951
Assignees
Labels
Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Nov 12, 2019

function Decorator() {
    return (target: new (...args: any[]) => any) => {};
}

try {
    @Decorator()
    class MyClass {
        public static func(): MyClass {
            return new MyClass();
        }
    }
}
catch (e)
{
}

Current Emit

try {
    var MyClass_1 = /** @class */ (function () {
        function MyClass() {
        }
        MyClass_2 = MyClass_1;
        MyClass.func = function () {
            return new MyClass_2();
        };
        var MyClass_2;
        MyClass_1 = MyClass_2 = __decorate([
            Decorator()
        ], MyClass_1);
        return MyClass;
    }());
}
catch (e) {
}

Expected Emit

try {
    var MyClass = /** @class */ (function () {
        function MyClass() {
        }
        MyClass_1 = MyClass;
        MyClass.func = function () {
            return new MyClass_1();
        };
        var MyClass_1;
        MyClass = MyClass_1 = __decorate([
            Decorator()
        ], MyClass);
        return MyClass;
    }());
}
catch(e) {
}
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript labels Nov 12, 2019
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.8.0 milestone Nov 12, 2019
@wimoy
Copy link

wimoy commented Nov 12, 2019

The issue is that the MyClass_1 argument in the __decorate([..]) function call is undefined.

The expected emit should be similar to the emit without the try/catch block:

try {
    var MyClass = /** @class */ (function () {
        function MyClass() {
        }
        MyClass_1 = MyClass;
        MyClass.func = function () {
            return new MyClass_1();
        };
        var MyClass_1;
        MyClass = MyClass_1 = __decorate([
            Decorator()
        ], MyClass);
        return MyClass;
    }());
}
catch(e)
{
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants