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

Decorator emits undefined default_1 #14591

Closed
Igorbek opened this issue Mar 11, 2017 · 0 comments
Closed

Decorator emits undefined default_1 #14591

Igorbek opened this issue Mar 11, 2017 · 0 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Igorbek
Copy link
Contributor

Igorbek commented Mar 11, 2017

TypeScript Version: 2.2.1

tsconfig.json

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "module": "es2015",
        "target": "es2015"
    }
}

Code

declare const decorator: PropertyDecorator;

export default class {
    @decorator a = 1;
}

Expected emit:

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;
};
const default_1 = class {
    constructor() {
        this.a = 1;
    }
}
__decorate([
    decorator
], default_1.prototype, "a", void 0);

export default default_1;

Actual emit:

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;
};
export default class {
    constructor() {
        this.a = 1;
    }
}
__decorate([
    decorator
], default_1.prototype, "a", void 0);

As a result, a run-time error thrown 'default_1 is not defined'

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

No branches or pull requests

4 participants